using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.TestDrivens;
using Pixysoft.Framework.Logs.Core;

namespace Pixysoft.Framework.Logs.TestCases
{
    [TestDriven(TestDrivenType.UnitTest, "LogIdCommand")]
    class UnitTest_022_LogIdCommand
    {
        private static IAssert assert = Assert.New(true);

        [TestCase("ExecuteReader")]
        public static void TestCase_000_ExecuteReader()
        {
            string path = StringFilter.RegularPath(AppDomain.CurrentDomain.BaseDirectory);
            string filename = "pixysoft";
            string postfix = ".log";

            CoreLogger logger = new CoreLogger(filename, null);
            logger.Setting.LogPath = path;

            assert.Write(logger.Info("hello<>&$#@!${}[];'"));
            string id = logger.Debug("hello<>&$#@!${}[];'");
            assert.Write(id);
            assert.Write(logger.Warn("hello<>&$#@!${}[];'"));
            assert.Write(logger.Error("hello<>&$#@!${}[];'"));
            assert.Write(logger.Fatal("hello<>&$#@!${}[];'"));
            logger.Close();

            SingletonLogger.Backup(path, filename, postfix);


            LogIdCommand command = new LogIdCommand(path, filename + postfix, id);
            command.CrossFiles = false;
            ILogRecord rec = command.ExecuteReader();
            assert.IsNull(rec);


            command = new LogIdCommand(path, filename + postfix, id);
            command.CrossFiles = true;
            rec = command.ExecuteReader();
            assert.IsNotNull(rec);
            assert.IsEqual(id, rec.Id);
        }

    }
}
